package com.xindaoapp.framework.api;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.util.ByteArrayBuffer;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Pair;

import com.alibaba.fastjson.JSON;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.xindaoapp.framework.bean.AddressDetailInfo;
import com.xindaoapp.framework.bean.AddressInfo;
import com.xindaoapp.framework.bean.ConsigneeInfo;
import com.xindaoapp.framework.bean.InformMessage;
import com.xindaoapp.framework.bean.PrivateMessageInfo;
import com.xindaoapp.framework.bean.ReplyInfo;
import com.xindaoapp.framework.bean.ShoppingCartInfo;
import com.xindaoapp.framework.bean.UpdateInfo;
import com.xindaoapp.framework.http.XDHttpClient;
import com.xindaoapp.framework.utils.CommonUtil;
import com.xindaoapp.framework.utils.IRequest;

public class MoccaApiImpl implements MoccaApi {

	private static final Handler mHandler = new Handler();

	@Deprecated
	@Override
	public void publishPost(String uid, String jid, String title, String content, File[] files, String type,
			File videoimg, final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_UID, uid);
		params.add(PARAM_FID, jid);
		params.add(PARAM_TITLE, title);
		params.add(PARAM_CONTENT, content);

		if (!TextUtils.isEmpty(type)) {
			params.add(PARAM_TYPE, type);
			if (type.equals(VIDEO)) {
				try {
					params.put(PARAM_VIDEOIMG, videoimg);
					if (null != files) {
						for (int i = 0; i < files.length; i++) {
							params.put("video", files[i]);
						}
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
			} else if (type.equals(IMG)) {}
		}

		XDHttpClient.post(INDEXPOSTS, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				iRequest.request(true);
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(false);
			}
		});
	}

	

	private static File compressImage(File file) {
		if (file.length() >= 500 * 1024) {// 文件大于500K，进行压缩
			String path = Environment.getExternalStorageDirectory() + File.separator + "thumbnail"
					+ File.separator + System.currentTimeMillis() + ".jpg";
			try {
				File targetFile = new File(Environment.getExternalStorageDirectory() + File.separator
						+ "thumbnail");
				if (!targetFile.exists()) {
					targetFile.mkdir();
				}
				CommonUtil.scalePicture(file.getAbsolutePath(), path, 8);
			} catch (Exception e) {
				e.printStackTrace();
			}
			file = new File(path);// 将之前的文件替换为新的文件
		}
		return file;
	}



	protected static final int BUFFER_SIZE = 4096;

	static byte[] getResponseData(HttpEntity entity) throws IOException {
		byte[] responseBody = null;
		if (entity != null) {
			InputStream instream = entity.getContent();
			if (instream != null) {
				long contentLength = entity.getContentLength();
				if (contentLength > Integer.MAX_VALUE) {
					throw new IllegalArgumentException("HTTP entity too large to be buffered in memory");
				}
				int buffersize = (contentLength < 0) ? BUFFER_SIZE : (int) contentLength;
				try {
					ByteArrayBuffer buffer = new ByteArrayBuffer(buffersize);
					try {
						byte[] tmp = new byte[BUFFER_SIZE];
						int l, count = 0;
						// do not send messages if request has been cancelled
						while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
							count += l;
							buffer.append(tmp, 0, l);
							// sendProgressMessage(count, (int) contentLength);
						}
					} finally {
						instream.close();
					}
					responseBody = buffer.toByteArray();
				} catch (OutOfMemoryError e) {
					System.gc();
					throw new IOException("File too large to fit into available memory");
				}
			}
		}
		return responseBody;
	}

	@Override
	public void checkUpdate(final IRequest<UpdateInfo> iRequest) {
		RequestParams params = new RequestParams();
		XDHttpClient.get2(CHECKUPDATE, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					UpdateInfo info = JSON.parseObject(new JSONObject(content).getJSONObject("apk")
							.toString(), UpdateInfo.class);
					iRequest.request(info);
				} catch (JSONException e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void getShoppingCart(String userId, final IRequest<ArrayList<ShoppingCartInfo>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userId);
		XDHttpClient.post2(SHOPBASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					ArrayList<ShoppingCartInfo> shoppingCartInfos = new ArrayList<ShoppingCartInfo>();
					shoppingCartInfos.addAll(JSON.parseArray(JSON.parseObject(content).getJSONArray(DATA)
							.toJSONString(), ShoppingCartInfo.class));
					iRequest.request(shoppingCartInfos);
				} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(new ArrayList<ShoppingCartInfo>());
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void getConsigneeCart(IRequest<List<ConsigneeInfo>> iRequest) {

	}

	@Override
	public void deleteShoppingCart(String userId, String recID, final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userId);
		params.add(PARAM_RECID, recID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=order&m=delCart", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getInteger("status") == 1 ? true
									: false);
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(false);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(false);
					}
				});
	}

	@Override
	public void editCart(String userID, int goodsNumber, String recID,
			final IRequest<Pair<Boolean, String>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, String.valueOf(userID));
		params.add(PARAM_GOODSNUMBER, String.valueOf(goodsNumber));
		params.add(PARAM_RECID, recID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=order&m=editCart", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(new Pair<Boolean, String>(JSON.parseObject(content).getInteger(
									"status") == 1 ? true : false, JSON.parseObject(content).getString(MSG)));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void addAddress(String userId, int provincesID, int cityID, int areaID, String address,
			String userName, String code, String phone, String email, String addressID,
			final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, String.valueOf(userId));
		params.add(PARAM_PROVINCESID, String.valueOf(provincesID));
		params.add(PARAM_CITYID, String.valueOf(cityID));
		params.add(PARAM_AREAID, String.valueOf(areaID));
		params.add(PARAM_ADDRESS, address);
		params.add(PARAM_USERNAME, userName);
		params.add(PARAM_CODE, code);
		params.add(PARAM_PHONE, phone);
		if (!TextUtils.isEmpty(addressID)) {
			params.add(PARAM_ADDRESSID, addressID);
		}
//		params.add(PARAM_EMAIL, email);
		XDHttpClient.post2(
				TextUtils.isEmpty(addressID) ? "http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=addAddress"
						: "http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=editAddress", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getInteger(STATUS) == 1 ? true : false);
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(false);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(false);
					}
				});
	}

	@Override
	public void deleteAddress(String userID, String addressID, final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_ADDRESS, addressID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=delAddress", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getInteger("status") == 1 ? true
									: false);
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(false);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(false);
					}
				});
	}

	@Override
	public void editAddress(String userId, int provincesID, int cityID, int areaID, String address,
			String userName, String code, String phone, String email, String addressID,
			final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, String.valueOf(userId));
		params.add(PARAM_PROVINCESID, String.valueOf(provincesID));
		params.add(PARAM_CITYID, String.valueOf(cityID));
		params.add(PARAM_AREAID, String.valueOf(areaID));
		params.add(PARAM_ADDRESS, address);
		params.add(PARAM_USERNAME, userName);
		params.add(PARAM_CODE, code);
		params.add(PARAM_PHONE, phone);
//		params.add(PARAM_EMAIL, email);
		params.add(PARAM_ADDRESSID, addressID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=editAddress", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getInteger("status") == 1 ? true
									: false);
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(false);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(false);
					}
				});
	}

	@Override
	public void getMyAddress(String userID, final IRequest<List<AddressInfo>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, String.valueOf(userID));
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=myAddress", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseArray(JSON.parseObject(content).getJSONArray(DATA)
									.toJSONString(), AddressInfo.class));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void getMyAddressDetail(String userID, String addressID, final IRequest<AddressDetailInfo> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_ADDRESSID, addressID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=addressDetail", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(JSON.parseObject(content).getJSONObject(DATA)
									.toJSONString(), AddressDetailInfo.class));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void setDefaultAddressDetail(String userID, String addressID, final IRequest<Boolean> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_ADDRESSID, addressID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=setAddressDefault", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getInteger("status") == 1 ? true
									: false);
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(false);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(false);
					}
				});
	}

	@Override
	public void getDefaultAddress(String userID, final IRequest<AddressDetailInfo> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=goods&m=getDefaultAddress", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(JSON.parseObject(content).getJSONObject(DATA)
									.toJSONString(), AddressDetailInfo.class));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void addOrder(String userID, String addressID, String recID, String order_amount,
			String shipping_fee, String postscript, final IRequest<String> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_ADDRESSID, addressID);
		params.add(PARAM_RECID, recID);
		params.add(PARAM_ORDER_AMOUNT, order_amount);
		params.add(PARAM_SHIPPING_FEE, shipping_fee);
		params.add(PARAM_POSTSCRIPT, postscript);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=order&m=addOrder", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							if (JSON.parseObject(content).getInteger(STATUS) == 1) {
								iRequest.request(JSON.parseObject(content).getJSONObject(DATA)
										.getString(ORDER_SN));
							} else {
								iRequest.request(null);
							}
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void getCartList(String userID, final IRequest<String> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=order&m=addOrder", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							if (JSON.parseObject(content).getInteger(STATUS) == 1) {
								iRequest.request(JSON.parseObject(content).getJSONObject(DATA)
										.getString(ORDER_SN));
							} else {
								iRequest.request(null);
							}
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void getReplyList(String userID, int page, int pageSize, final IRequest<List<ReplyInfo>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_PAGE, String.valueOf(page));
		params.add(PARAM_PAGESIZE, String.valueOf(pageSize));
		XDHttpClient.post2("http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=notice_post_list",
				params, new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseArray(JSON.parseObject(content).getJSONArray(ARRAY)
									.toJSONString(), ReplyInfo.class));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void getInformMessageList(String userID, int page, int pageSize,
			final IRequest<List<InformMessage>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_USERID, userID);
		params.add(PARAM_PAGE, String.valueOf(page));
		params.add(PARAM_PAGESIZE, String.valueOf(pageSize));
		XDHttpClient.post2("http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=notice_sys_list",
				params, new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseArray(JSON.parseObject(content).getJSONArray(ARRAY)
									.toJSONString(), InformMessage.class));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void deleteInformMessage(String notice_id, final IRequest<Pair<Boolean, String>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_NOTICEID, notice_id);
		XDHttpClient.post2("http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=notice_delete",
				params, new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(new Pair<Boolean, String>(JSON.parseObject(content).getInteger(
									RESULT) == 0 ? true : false, JSON.parseObject(content).getString("msg")));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(null);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(null);
					}
				});
	}

	@Override
	public void getPrivateMessageList(final IRequest<List<PrivateMessageInfo>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_ID, LEEPET_THREAD_API);
		params.add(PARAM_ACTION, ACTION_MESSAGE_PRIVATE_LIST);
		XDHttpClient.post2(BASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void getPrivateMessageListWithUid(String touid, final IRequest<List<PrivateMessageInfo>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_ID, LEEPET_THREAD_API);
		params.add(PARAM_ACTION, ACTION_MESSAGE_PRIVATE_SHOW);
		params.add(PARAM_TOUID, touid);
		params.add(PARAM_PAGE, "0");
		params.add(PARAM_PAGESIZE, "100");
		XDHttpClient.post2(BASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					iRequest.request(JSON.parseArray(JSON.parseObject(content).getJSONArray(ARRAY)
							.toJSONString(), PrivateMessageInfo.class));
				} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void sendPrivateMessage(String username, String message,
			final IRequest<Pair<Boolean, String>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_ID, LEEPET_THREAD_API);
		params.add(PARAM_ACTION, ACTION_MESSAGE_SEND);
		params.add(PARAM_USERNAME_, username);
		params.add(PARAM_MESSAGE, message);
		XDHttpClient.post2(BASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					iRequest.request(new Pair<Boolean, String>(
							JSON.parseObject(content).getInteger(RESULT) == 0 ? true : false, JSON
									.parseObject(content).getString("msg")));
				} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void ignorePrivateMessageWithUid(String username, final IRequest<Pair<Boolean, String>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_ID, LEEPET_THREAD_API);
		params.add(PARAM_ACTION, ACTION_MESSAGE_IGNORE);
		params.add(PARAM_TOUSERNAME, username);
		XDHttpClient.post2(BASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					iRequest.request(new Pair<Boolean, String>(
							JSON.parseObject(content).getInteger(RESULT) == 0 ? true : false, JSON
									.parseObject(content).getString("msg")));
				} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void deletePrivateMessageWithUid(String touid, String pmid,
			final IRequest<Pair<Boolean, String>> iRequest) {
		RequestParams params = new RequestParams();
		params.add(PARAM_ID, LEEPET_THREAD_API);
		params.add(PARAM_ACTION, ACTION_MESSAGE_DELETE);
		params.add(PARAM_TOUID, touid);
		params.add(PARAM_PMID, pmid);
		XDHttpClient.post2(BASEURL, params, new AsyncHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, String content) {
				super.onSuccess(statusCode, content);
				try {
					iRequest.request(new Pair<Boolean, String>(
							JSON.parseObject(content).getInteger(RESULT) == 0 ? true : false, JSON
									.parseObject(content).getString("msg")));
				} catch (Exception e) {
					e.printStackTrace();
					iRequest.request(null);
				}
			}

			@Override
			public void onFailure(Throwable error, String content) {
				super.onFailure(error, content);
				iRequest.request(null);
			}
		});
	}

	@Override
	public void getFreight(String recID, int provinceID, final IRequest<Float> iRequest) {
		RequestParams params = new RequestParams();
		params.add("recID", recID);
		params.add("provinceID", String.valueOf(provinceID));
		XDHttpClient.post2("http://ts.leepet.com/plugins/API.v1.0/?&a=order&m=getShippingFee", params,
				new AsyncHttpResponseHandler() {

					@Override
					public void onSuccess(int statusCode, String content) {
						super.onSuccess(statusCode, content);
						try {
							iRequest.request(JSON.parseObject(content).getJSONObject(DATA)
									.getFloat("shipping_fee"));
//							iRequest.request(new Pair<Boolean, String>(JSON.parseObject(content).getInteger(
//									RESULT) == 0 ? true : false, JSON.parseObject(content).getString("msg")));
						} catch (Exception e) {
							e.printStackTrace();
							iRequest.request(0f);
						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);
						iRequest.request(0f);
					}
				});
	}
}
